'use strcit'

function reqq(resolve,reject){
    setTimeout(()=>{
        let rnd = parseInt(Math.random()*2);
        if(rnd===1){
            resolve(rnd)
        }else{
            reject(rnd)
        }
    });
}

// reqq(console.log,console.log);

let p1=new Promise(reqq);

p1.then((t)=>{
    console.log(t);
}).catch((b)=>{
    console.log(b);
})

console.log(Promise);


function add(x){
    return new Promise(function(resolve,reject){
        console.log(`学霸题算加法,现在x=${x}`);
        setTimeout(resolve,500,x + x)
    })
}

function multipx(x){
    return new Promise(function(resolve,reject){
        setTimeout(()=>{
            console.log(`学霸题算乘法,现在x=${x}`);
            resolve(x * x)
        },800)
    })
}

let p = new Promise(function(resolve,reject){
    console.log(`写作业了`);
    resolve(10);
})

p.then(add)
.then(add)
.then(add)
.then(add)
.then(add)
.then(add)
.then(add)
.then(multipx)
.then((x)=>{
    console.log('做完了');
    console.log(x);
})